package me.ak.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import me.ak.file.Saveable;
import me.ak.utils.CManip;

import org.jnbt.CompoundTag;
import org.jnbt.IntTag;
import org.jnbt.Tag;

public class ChordModel extends Model implements Saveable {

	private int length; //1 = 64th note, 2 = 32nd, ect.
	private List<Integer> notes = new ArrayList<Integer>();
	private int index;

	public ChordModel(int[] n, int length) {
		this.length = length;
		for (int i : n) notes.add(new Integer(i));
	}
	
	public int getLength() {
		return length;
	}
	
	/**
	 * @return The index of the chord inside the bar. Only used for reading after saving.
	 */
	public int getIndex() {
		return index;
	}
	
	public void setIndex(int i) {
		index = i;
	}
	
	public List<Integer> getNotesList() {
		return notes;
	}
	
	public int[] getNotesArray() {
		int[] ar = new int[notes.size()];
		for (int i = 0; i < notes.size(); i ++) {
			ar[i] = notes.get(i);
		}
		return ar;
	}
	
	
	
	
	
	public CompoundTag saveNBT() {
		HashMap<String, Tag> noteRoot = CManip.initMap();
		for (int i = 0; i < notes.size(); i++) {
			IntTag it = new IntTag("NoteValue", notes.get(i));
			IntTag nl = new IntTag("NoteLength", length);
			HashMap<String, Tag> inNoteRoot = CManip.initMap();
			inNoteRoot.put("NoteValue", it);
			inNoteRoot.put("NoteLength", nl);
			noteRoot.put("Note", new CompoundTag("Note", inNoteRoot));
			
		}
		noteRoot.put("BarIndex", new IntTag("BarIndex", index));
		return new CompoundTag("Chord", noteRoot);
	}

	@Override
	public void readNBT(CompoundTag t) {
		// TODO Auto-generated method stub

	}

}
